<?php
    class HotelController extends Main_Controller_Action
    {
        private $_arrParam;
        private $_model;

        public function init()
        {
            $this->loadTemplates();
            $this->_arrParam = $this->_request->getParams();
            $this->_model = new Default_Model_Hotel();
            if(isset($this->_arrParam['lang'])) {
                $this->view->lang = $this->_arrParam['lang'];
            }
            else {
                $this->view->lang = 'vi';
            }
        }

        public function indexAction()
        {
            $this->view->headTitle('Julytour - Khách sạn');
            $adapter = new Zend_Paginator_Adapter_DbSelect($this->_model->listItem($this->view->lang));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;
        }

        public function tagAction()
        {
            $tag_id = (int) $this->_arrParam['id'];
            $this->view->headTitle('Julytour - Khách sạn');
            $adapter = new Zend_Paginator_Adapter_DbSelect($this->_model->listItemByTag($tag_id, $this->view->lang));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;
        }

        public function areaAction()
        {
            $area_id = (int) $this->_arrParam['id'];
            $this->view->headTitle('Julytour - Khách sạn');
            $adapter = new Zend_Paginator_Adapter_DbSelect($this->_model->listItemByArea($area_id, $this->view->lang));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;

            $location = new Default_Model_Location();
            $this->view->locationName = $location->getLocationNameById($area_id, $this->view->lang);
        }

        public function locationAction()
        {
            $location_id = (int) $this->_arrParam['id'];
            $this->view->headTitle('Julytour - Khách sạn');
            $adapter = new Zend_Paginator_Adapter_DbSelect($this->_model->listItemByLocation($location_id, $this->view->lang));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;

            $location = new Default_Model_Location();
            $this->view->locationName = $location->getLocationNameById($location_id, $this->view->lang);
        }

        public function detailsAction()
        {
            $id     = (int) $this->_arrParam['id'];
            $image  = new Default_Model_Image();
            $room   = new Default_Model_Room();
            $sales  = new Default_Model_Sales();
            $this->view->data   = $this->_model->getItem($id, $this->view->lang);
            $this->view->image  = $image->getItem(1, $id, $this->view->lang);
            $this->view->room   = $room->getItem(1, $id, $this->view->lang);
            $this->view->sales  = $sales->getSalesByType(1, $id, $this->view->lang);
            $this->view->headTitle('Julytour - '.$this->view->data['name']);
        }
    }
